
import Taro from '@tarojs/taro';
import { apiServiceK } from '../../env.config';


export default (options = {}) => {
  return Taro.request({
    url: options.url ? apiServiceK + options.url : apiServiceK,
    data: {...options.data} || {},
    header: options.header || {
      'Content-Type': 'application/json',
    },
    method: options.method ? options.method.toUpperCase() : 'GET',

  }).then((res) => {
    const { statusCode, data } = res

    if (statusCode >= 200 && statusCode < 300) {
      return data

    } else {
      throw new Error(`网络请求错误，状态码${statusCode}`)
    }
  }).catch((err) => {
    console.log('请求错误-err', err);
  })
}
